package cn.hjh.util;


import cn.hjh.dao.HibernateUtil;
import org.hibernate.Filter;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;


import java.io.IOException;
import java.util.Collection;

public class OpenSessionInViewFilter implements Filter {

    public void doFilter(ServletRequest arg0,ServletResponse arg1,FilterChain arg2)throws Exception{
        Transaction tx = null;
        try {
            tx = HibernateUtil.currentSession().beginTransaction();
            arg2.doFilter(arg0,arg1);
            tx.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            if (tx != null)
                tx.rollback();
        }
    }

}
